<template>
  <div>
    <el-drawer :visible.sync="drawer" direction="rtl" size="50%" :with-header="false" :width="700">
      <div class="drawer_box">
        <div class="drawer_title">
          <div class="drawer_t">
            <div class="drawer_t_l">
              <img class="drawer_t_l_img" src="/static/skin/herodoo/main/platform/home/img/piliangoumai.png" alt="" />
              查看订单
            </div>
            <img class="drawer_t_r" src="/static/skin/herodoo/main/platform/home/img/guanbi.png" alt=""
              @click="drawer = false" />
          </div>
        </div>
        <div class="drawer_content">
          <div class="content-box">
            <div class="label">订单编号:</div>
            <div class="desc">
              {{ messageList.Code }}
              <div class="states" :style="getState(messageList.STATUSID, 'STATUS').style">
                {{ messageList.STATUS }}
              </div>
            </div>
          </div>
          <div class="content-box">
            <div class="label">权益名称:</div>
            <div class="desc name" @click="drawerUpDetail">
              {{ messageList.Name }}
            </div>
          </div>
          <div class="content-box" v-if="messageList.TypeID == 2">
            <div class="label">包含权益:</div>
            <div class="desc">
              <div class="rightsList">
                <div class="rights_son_box" v-if="alreadyList && alreadyList != false">
                  <div class="rights_son" v-for="item in alreadyList" :key="item.ID">
                    <div class="rights_son_title">{{ item.Name }}</div>
                  </div>
                </div>
                <div class="rights_son_box" v-if="buyList && buyList != false">
                  <div class="rights_son" v-for="item in buyList" :key="item.ID">
                    <div class="rights_son_title">{{ item.Name }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="content-box">
            <div class="label">产品名称:</div>
            <div class="desc">{{ messageList.ProductName }}</div>
          </div>
          <div class="content-box">
            <div class="label">产品类型:</div>
            <div class="desc" v-if="messageList.ProductFlagListName">
              <div class="rights-tag auth-tag" v-for="(item, index) in messageList.ProductFlagListName.split(
                ','
              )" :key="index" effect="plain">
                {{ item }}
              </div>
            </div>
          </div>
          <div class="content-box">
            <div class="label">购买数量:</div>
            <div class="desc">{{ messageList.Quantity }}</div>
          </div>
          <!-- <div class="content-box">
                    <div class="label">乘车人数:</div>
                    <div class="desc">{{ messageList.UsersCount }}</div>
                </div> -->
          <block v-for="item in peopleData" :key="item.ID">
            <div class="content-box">
              <div class="label">联系人:</div>
              <div class="desc">{{ item.Name }}</div>
            </div>
            <div class="content-box">
              <div class="label">联系方式:</div>
              <div class="desc">{{ item.Mobile }}</div>
            </div>
          </block>
          <div class="content-box">
            <div class="label">备注:</div>
            <div class="desc">{{ messageList.Remarks }}</div>
          </div>
          <div class="content-box">
            <div class="label">平台价格:</div>
            <div class="desc">{{ messageList.CostPrice }}</div>
          </div>
          <div class="content-box">
            <div class="label">下单金额(元):</div>
            <div class="desc">{{ messageList.TotalPrice }}</div>
          </div>
          <div class="content-box">
            <div class="label">购买渠道:</div>
            <div class="desc">{{ messageList.PlatformID }}</div>
          </div>
          <div class="content-box">
            <div class="label">服务方:</div>
            <div class="desc">{{ messageList.ServiceCompanyName }}</div>
          </div>
          <div class="content-box">
            <div class="label">使用积分:</div>
            <div class="desc">{{ messageList.Integration }}</div>
          </div>
          <div class="content-box">
            <div class="label">卖家:</div>
            <div class="desc">{{ messageList.PurchaseCompanyName }}</div>
          </div>
          <div class="content-box" v-if="messageList.STATUSID != 20">
            <div class="label">下单时间:</div>
            <div class="desc">{{ messageList.CreateTime }}</div>
          </div>
          <div v-if="showSendCar && senCarList.length">
            <div class="content-box">
              <div class="label">使用时间:</div>
              <div class="desc">{{ senCarList[0].VerificeTime }}</div>
            </div>
            <div class="content-box">
              <div class="label">到达时间:</div>
              <div class="desc">{{ senCarList[0].ConfirmTime }}</div>
            </div>
            <div class="content-box">
              <div class="label">完成时间:</div>
              <div class="desc">{{ senCarList[0].ConfirmTime }}</div>
            </div>
          </div>
          <div class="content-box" v-if="messageList.STATUSID == 20">
            <div class="label">取消时间:</div>
            <div class="desc">{{ messageList.UpdateTime }}</div>
          </div>
          <!-- 派车信息 -->
          <div class="block" v-if="showSendCar && senCarList.length">
            <div class="title2">派车信息：</div>
            <div v-for="(item, index) in senCarList" :key="index">
              <div class="content-box">
                <div class="label">车型:</div>
                <div class="desc">{{ item.TypeIDName }}</div>
              </div>
              <div class="content-box">
                <div class="label">车牌号:</div>
                <div class="desc">{{ item.CarCode }}</div>
              </div>
              <div class="content-box">
                <div class="label">司机:</div>
                <div class="desc">{{ item.DriverName }}</div>
              </div>
              <div class="content-box">
                <div class="label">工号:</div>
                <div class="desc">{{ item.DriverCode }}</div>
              </div>
              <div class="content-box">
                <div class="label">司机联系方式:</div>
                <div class="desc">{{ item.Mobile }}</div>
              </div>
            </div>
            <br />
            <div class="content-box">
              <div class="label">调度人:</div>
              <div class="desc">{{ senCarList[0].ConfirmName }}</div>
            </div>
            <div class="content-box">
              <div class="label">工号:</div>
              <div class="desc">{{ senCarList[0].ConfirmCode }}</div>
            </div>
            <div class="content-box">
              <div class="label">派车时间:</div>
              <div class="desc">{{ senCarList[0].ConfirmTime }}</div>
            </div>
          </div>

          <!-- 核销码列表 -->
          <div class="block" v-if="false">
            <div class="title2">核销码列表:</div>
            <div class="content-box">
              <el-table :data="cancelData" stripe style="width: 100%">
                <el-table-column prop="VerificeCode" label="核销码" width="300">
                </el-table-column>
                <el-table-column prop="PurchaserName" label="买家">
                </el-table-column>
                <el-table-column prop="Status" label="使用状态" width="80">
                  <template slot-scope="scope">
                    {{ scope.row.VerificeTime ? '已核销' : '待核销' }}
                  </template>
                </el-table-column>
                <el-table-column prop="EquityName" label="权益名称" width="180">
                </el-table-column>
              </el-table>
            </div>
            <div class="end" v-if="cancelTotal > 0">
              <el-pagination background layout="prev, pager, next" :total="cancelTotal" :current-page="cancelPage"
                :page-size="pageSize" @current-change="handleCancelChange">
              </el-pagination>
            </div>
          </div>
        </div>

        <div class="drawer_footer">
          <!-- 待确认 -->
          <div class="footer-btn" v-if="messageList.STATUSID == 11" @click="openAssigeCar">
            派车
          </div>
          <!-- 已确认 -->
          <div class="footer-btn" v-if="messageList.STATUSID == 13" @click="openAssigeCar">
            重新派车
          </div>
          <!-- 待评价、已完成、已取消 中取消订单不展示 -->
          <div class="footer-btn reject" v-if="isShowCancel" @click="handleCancel">
            取消订单
          </div>
        </div>
      </div>
    </el-drawer>
    <AssigeCar :messageList="messageList" ref="AssigeCar" @drawerUpDetail="drawerUpDetail" @refresh="$emit('refresh')">
    </AssigeCar>
    <!-- 查看权益详情 -->
    <rights-detail :octopus="octopus" ref="rightsDetail"></rights-detail>
    <!-- 取消订单 -->
    <cancel-order :messageList="messageList" :octopus="octopus" ref="cancelOrder"
      @drawerUpDetail="drawerUpDetail"></cancel-order>
  </div>
</template>

<script>
import orderStatus from "./orderStatus";
import AssigeCar from "./assigeCar.vue";
import rightsDetail from "./rightsDetail.vue";
import CancelOrder from "./CancelOrder.vue";
export default {
  name: "look_dialog",
  components: {
    rightsDetail,
    AssigeCar,
    CancelOrder
  },
  props: {
    messageList: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      drawer: false,
      rightList: [],
      tabID: 2,
      peopleData: [],
      cancelData: [],
      senCarList: [],
      states: {
        name: "订单状态",
        is_index: 0,
        is_type: "",
        arr: orderStatus
      },
      total: 0,
      currentPage: 1, //当前页
      pageSize: 10, // 每页显示条数
      cancelTotal: 0,
      cancelPage: 1,
      buyList: [],
      alreadyList: []
    };
  },
  watch: {
    drawer(v) {
      if (v) {
        // this.getRightList()
        this.getUseCount();
        this.getCancelCode();
        this.getSendCar();
      }
      // 在这里可以执行其他操作
    },
    showSendCar() {
      return (
        this.messageList.STATUSID != 1 &&
        this.messageList.STATUSID != 10 &&
        this.messageList.STATUSID != 11
      );
    }
  },
  computed: {
    isShowCancel() {
      // this.octopus.passport.authorization.company != 1 &&
      return (
        this.messageList.STATUSID == 10 ||
        this.messageList.STATUSID == 11 ||
        this.messageList.STATUSID == 13 ||
        this.messageList.STATUSID == 15
      );
    }
  },
  mounted() { },
  methods: {
    drawerOp() {
      this.drawer = true;
      this.buyList = [];
      this.alreadyList = [];

      if (this.messageList.TypeID == 2) {
        this.getCompileData().then(res => {
          res.map(v => {
            if (v.CompanyID == this.messageList.CompanyID) {
              this.alreadyList.push(v);
            } else {
              this.buyList.push(v);
            }
          });
        });
      }
    },
    changeTab(e) {
      this.tabID = e;
    },
    // 获取权益详情
    getCompileData() {
      return new Promise((resolve, reject) => {
        let o = this;
        o.octopus.request.api.post(
          "/Octopus/Engine/List",
          {
            id: 1184,
            cellData: [
              { name: "CostPrice" }, // 平台价格
              { name: "CompanyID" }, // 子权益公司ID
              { name: "FlagList" }, // 权益标签
              { name: "FlagListName" }, // 权益标签
              { name: "ID" }, // ID
              { name: "Name" }, // 权益标题
              { name: "SalePrice" }, // 市场价格
              { name: "SoldQuantity" }, // 已售数量
              { name: "TypeID" }, // 权益类型
              { name: "ExpireTime" }, // 到期时间
              { name: "EffectiveTime" }, // 生效时间
              { name: "InventoryQuantity" }, // 库存数量
              { name: "SoldQuantity" }, // 已售数量
              { name: "EquityCount" }, // 权益数量
              { name: "EquityServiceRate" }, // 小程序服务费
              { name: "PlatformServiceRate" }, // 平台服务费
              { name: "UserCount" } // 使用人数
            ],
            paramData: {
              ID: o.messageList.EquityID
            }
          },
          data => {
            if (data.status.code == 200) {
              resolve(data.content.queryData);
            } else {
              o.octopus.tips.error(data);
              reject(false);
            }
          }
        );
      });
    },
    getState(i, type) {
      let obj = {};
      if (type == "index") {
        this.states.arr.filter((item, o) => {
          if (o == i) {
            obj = item;
          }
        });
      }
      if (type == "id" || type == "type") {
        this.states.arr.filter(item => {
          if (item[type] == i) {
            obj = item;
          }
        });
      }
      if (type.toLowerCase() == "status") {
        this.states.arr.filter(item => {
          if (item.name == i) {
            obj = item;
          }
        });
      }
      obj.style = `color:${obj.color};background:${obj.bgColor};borderColor:${obj.color
        }`;
      return obj;
    },
    // 售卖情况
    getRightList() {
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 605,
          cellData: [
            { name: "Code" }, // 订单编号
            { name: "CostPrice" }, // 平台价格
            { name: "CreateTime" }, // 下单时间
            { name: "EquityFlagList" }, // 权益标签id
            { name: "EquityID" }, // 权益id
            { name: "Name" }, // 权益名称
            { name: "PlatformTypeID" }, // 购买渠道
            { name: "ProductFlagList" }, // 产品标签ID
            { name: "Purchaser" }, // 买家
            { name: "Quantity" }, // 数量
            { name: "Seller" }, // 卖家
            { name: "ServerCompanyID" }, // 服务方ID
            { name: "Status" }, // 订单状态
            { name: "TotalPrice" }, // 下单金额
            { name: "TransferRuleID" } // 采购公司限制
          ],
          paramData: {
            PurchaserCompanyID: this.messageList.PurchaserCompanyID,
            Code: this.messageList.Code,
            CompanyID: this.octopus.passport.authorization.company
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.rightList = data.content.queryData;
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },

    // 查看权益详情
    handleToRightsDetail() {
      this.$refs.rightsDetail.drawerOp();
    },

    handleCancel() {
      this.$refs.cancelOrder.drawerOp();
    },
    // 派车
    openAssigeCar() {
      this.$refs.AssigeCar.drawerOp();
      this.$refs.AssigeCar.updata();
    },
    // 展示权益详情
    drawerUpDetail() {
      this.$refs.rightsDetail.init(this.messageList.EquityID);
      this.$refs.rightsDetail.drawerOp(this.alreadyList, this.buyList);
    },
    // 使用人列表
    getUseCount() {
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1237,
          cellData: [
            { name: "ID" }, // ID
            { name: "IdentityNumber" }, // 证件号码
            { name: "Mobile" }, // 联系方式
            { name: "Name" }, // 姓名
            { name: "PurchaseID" }, // 订单
            { name: "TypeID" }, // 证件类型
            { name: "TypeIDName" } // 证件类型
          ],
          paramData: {
            ID: this.messageList.ID
          },
          pageData: {
            index: this.currentPage,
            rowSize: this.pageSize
          }
        },
        data => {
          if (data.status.code == 200) {
            this.peopleData = data.content.queryData;
            this.total = data.content.pageData.totalRows;
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 核销码列表列表
    getCancelCode() {
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1243,
          cellData: [
            { name: "EquityName" }, // 权益名称
            { name: "ID" }, // ID
            { name: "PurchaserName" }, // 买家
            { name: "Status" }, // 使用状态
            { name: "VerificeCode" }, // 核销码
            { name: "VerificeTime" } // VerificeTime
          ],
          paramData: {
            ID: this.messageList.ID
          },
          pageData: {
            index: this.cancelPage,
            rowSize: this.pageSize
          }
        },
        data => {
          if (data.status.code == 200) {
            this.cancelData = data.content.queryData;
            this.cancelTotal = data.content.pageData.totalRows;
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 派车信息列表
    getSendCar() {
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1246,
          cellData: [
            { name: "CarCode" }, // 车牌
            { name: "CompleteTime" }, // 完成时间| 到达时间
            { name: "ConfirmCode" }, // 调度人工号
            { name: "ConfirmID" }, // ConfirmID
            { name: "ConfirmName" }, // 调度人姓名
            { name: "ConfirmTime" }, // 调度时间（派车时间）
            { name: "Driver" }, // 司机
            { name: "DriverCode" }, // 司机工号
            { name: "DriverName" }, // 司机姓名
            { name: "ID" }, // ID
            { name: "Mobile" }, // 司机联系方式
            { name: "PurchaseID" }, // PurchaseID
            { name: "SystemID" }, // SystemID
            { name: "SystemIDName" }, // SystemIDName
            { name: "TypeID" }, // 车型
            { name: "TypeIDName" }, // 车型
            { name: "VerificeTime" } // 使用时间|核销时间
          ],
          paramData: {
            Code: this.messageList.Code
          }
        },
        data => {
          if (data.status.code == 200) {
            this.senCarList = data.content.queryData;
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },

    handleCurrentChange(val) {
      this.currentPage = val;
      this.getUseCount();
    },
    handleCancelChange(val) {
      this.cancelPage = val;
      this.getCancelCode();
    }
  }
};
</script>
<style scoped>
.drawer_box {
  padding: 3rem 0.8rem 3rem 0;
  height: calc(100% - 5rem);
  display: flex;
  flex-direction: column;
}

.drawer_title {
  box-shadow: 0px 5px 5px rgb(230 228 228 / 30%);
  padding: 1rem 0;
}

.title {
  font-size: 1.8rem;
  font-weight: bold;
  padding: 1rem 0;
}

.drawer_t {
  padding: 0 2.8rem;
  display: flex;
  justify-content: space-between;
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 2rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}

.button_box {
  margin-top: 1rem;
  padding: 0 3rem;
  display: flex;
}

.drawer_content {
  overflow-y: auto;
  margin-top: 1.5rem;
  height: calc(100vh - 13rem);
  padding: 0 3rem;
  width: 100%;
  padding-bottom: 1rem;
}

.drawer_content .title {
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_content .title2 {
  font-size: 1.8rem;
}

.drawer_content .driver-title {
  margin-top: 1em;
}

.content-box {
  display: flex;
  align-items: center;
  margin: 2rem 0 2rem 2em;
}

.mt-10 {
  margin-top: 20px;
}

.content-box .label {
  width: 25%;
}

.content-box .label .label-bold {
  font-size: 1.8rem;
  font-weight: bold;
}

.content-box .desc {
  /* flex: 1; */
  display: flex;
  flex-direction: row;
  align-items: center;
}

.name {
  color: #288ffd;
  text-decoration: underline;
  cursor: pointer;
}

.states {
  /* font-size: 1vw; */
  padding: 5px 10px;
  border: 1px solid #000;
  border-radius: 5px;
  margin-left: 20px;
}

.drawer_footer {
  display: flex;
  justify-content: flex-end;
  align-content: center;
}

.drawer_footer .footer-btn {
  line-height: 4rem;
  background-color: #f78c51;
  color: #fff;
  margin: 0 1rem;
  padding: 0 3rem;
  border-radius: 0.5rem;
  cursor: pointer;
}

.drawer_footer .reject {
  background-color: #2e3037;
}

.end {
  display: flex;
  justify-content: flex-end;
}

>>>.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #ff8a36;
}
</style>
